import request from '@/utils/request'
import { encrypt } from '@/utils/rsaEncrypt'

const userUrl = '/system/user'

export function listSysUser(data, page, size) {
  return request({
    url: `${userUrl}/listSysUser/` + page + '/' + size,
    method: 'post',
    data: data
  })
}

export function saveSysUser(data) {
  return request({
    url: `${userUrl}/saveSysUser`,
    method: 'post',
    data: data
  })
}

export function updateSysUser(data) {
  return request({
    url: `${userUrl}/updateSysUser`,
    method: 'put',
    data: data
  })
}

export function delSysUser(data) {
  return request({
    url: `${userUrl}/delSysUser`,
    method: 'delete',
    data: data
  })
}

export function resetPassword(data) {
  return request({
    url: `${userUrl}/resetPassword/` + data,
    method: 'put'
  })
}

export function exportSysUser(data) {
  return request({
    url: `${userUrl}/exportSysUser`,
    responseType: 'blob',
    method: 'post',
    data: data
  })
}

export function exportSysUserTemplate() {
  return request({
    url: `${userUrl}/exportSysUserTemplate`,
    responseType: 'blob',
    method: 'get'
  })
}

export function changeStatus(id, status) {
  return request({
    url: `${userUrl}/changeStatus/` + id + '/' + status,
    method: 'put'
  })
}

export function updatePass(user) {
  const data = {
    oldPass: encrypt(user.oldPass),
    newPass: encrypt(user.newPass)
  }
  return request({
    url: 'api/users/updatePass/',
    method: 'post',
    data
  })
}

export default {
  listSysUser,
  updatePass,
  saveSysUser,
  updateSysUser,
  delSysUser,
  resetPassword,
  exportSysUser,
  exportSysUserTemplate,
  changeStatus
}

